package com.cnswhy.cloud.server.common.entity.enumeration;

import com.cnswhy.cloud.common.core.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 转账类型的类型枚举
 * </p>
 *
 * @author cnswhy
 * @date 2020-10-24
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "PayType", description = "支付类型-枚举")
public enum PayType implements BaseEnum {

    /**
     * coupon=拼购券
     */
    alipay(2,"支付宝"),
    wx(3,"微信"),
    ;

    private int val;
    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 跟就当前枚举的name匹配
     */
    public static PayType match(String val, PayType def) {
        return Stream.of(values()).parallel().filter((item) -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static PayType get(String val) {
        return match(val, null);
    }

    public boolean eq(PayType val) {
        return val == null ? false : eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "alipay,wx", example = "alipay")
    public String getCode() {
        return this.name();
    }

}
